package icom.acm.action;
import java.text.SimpleDateFormat;
import java.util.Date;

import icom.acm.bean.T_U_BASEINFO;
import icom.acm.manager.T_U_BaseInfoMgr;

public class UserBaseInfoAction extends Action{
	private T_U_BASEINFO UBI;
	private int year;
	private int month;
	private int day;
	private String token;
	
	public String insertUpdateUBI(){
		// 防止重复提交
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		birthdayFormat();
		T_U_BaseInfoMgr uInfoMgr = new T_U_BaseInfoMgr();
		uInfoMgr.insertOrUpdate(UBI);
		return "SUCCESS";
	}
	
	private void birthdayFormat(){
		// 格式化生日
		SimpleDateFormat bartDateFormat =   new SimpleDateFormat("yyyy-MM-dd");  
		String dateStringToParse = year + "-" + month + "-" + day;
		final Date birthday;
		try{  
			   birthday = bartDateFormat.parse(dateStringToParse);
			   UBI.setU_BIRTHDAY(birthday);
		}  
		catch (Exception ex) {  
		     System.out.println(ex.getMessage());  
		}
	}
	
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public T_U_BASEINFO getUBI() {
		return UBI;
	}

	public void setUBI(T_U_BASEINFO ubi) {
		UBI = ubi;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}
}
